#ifndef RTPPARSE_SEQ_MANAGER_H
#define RTPPARSE_SEQ_MANAGER_H

#include <limits>
#include <set>
#include <stdint.h>

namespace Rtp {
    template<typename T, uint8_t N = 0>
    class SeqManager {
    public:
        static constexpr T MaxValue = (N == 0) ?  std::numeric_limits<T>::max() : ((1 << N) -1);
    public:
        struct SeqLowerThan {
            bool operator()(const T& lhs, const T& rhs) const;
        };

        struct SeqHigherThan {
            bool operator()(const T& lhs, const T& rhs) const;
        };

    public:
        static bool IsSeqHigherThan(T lhs, T rhs);
        static bool IsSeqLowerThan(T lhs, T rhs);

    public:
        SeqManager() = default;
        SeqManager(T initialOupt);

    public:
        void Sync(T input);
        void Drop(T input);
        bool Intput(T input, T& output);

        T GetMaxInput() const;
        T GetMaxOutput() const;

    private:
        void ClearDropped();

    private:
        bool started { false };
        T initialOutput { 0 };
        T base { 0 };
        T maxOutput { 0 };
        T maxInput { 0 };
        std::set<T, SeqLowerThan> dropped;
    };
}

#endif